package com.ruoyi.web.controller.formwork;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;

import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.expertmodel.domain.PerformanceModel;
import com.ruoyi.formwork.domain.BaseFormWork;
import com.ruoyi.formwork.service.BaseFormWorkService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ruoyi.common.core.domain.AjaxResult.success;

@RestController
@RequestMapping("/BaseFormWorkController")
public class BaseFormWorkController {

    @Resource
    private com.ruoyi.formwork.service.BaseFormWorkService BaseFormWorkService;

    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.setDisallowedFields(new String[]{"admin"});
    }

    @Log(title = "基线模板查询", businessType = BusinessType.QUERY)
    @PostMapping("/queryBaseFormWork")
    public AjaxResult queryBaseFormWork(@RequestBody BaseFormWork baseFormWork)
    {
        List<BaseFormWork> BaseFormWorks = BaseFormWorkService.queryBaseFormWork(baseFormWork);
        return success(BaseFormWorks);
    }

    @PreAuthorize("@ss.hasPermi('system:user:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response,  BaseFormWork baseFormWork)
    {
        List<BaseFormWork> BaseFormWorks = BaseFormWorkService.queryBaseFormWork(baseFormWork);

        ExcelUtil<BaseFormWork> util = new ExcelUtil<BaseFormWork>(BaseFormWork.class);

        util.exportExcel(response, BaseFormWorks, "基线模板");
    }
    @Log(title = "基线模板删除", businessType = BusinessType.DELETE)
    @PostMapping("/deleteBaseFormWork")
    public AjaxResult deleteBaseFormWork(@RequestBody BaseFormWork baseFormWork)
    {
        boolean b = BaseFormWorkService.deleteBaseFormWork(baseFormWork);
        if(b){
            return success("删除成功！");
        }else{
            return success("删除失败！");
        }

    }
    @Log(title = "基线模板新增", businessType = BusinessType.INSERT)
    @PostMapping("/addBaseFormWork")
    public AjaxResult addBaseFormWork(@RequestBody BaseFormWork baseFormWork)
    {
        boolean b = BaseFormWorkService.save(baseFormWork);
        if(b){
            return success("新增成功！");
        }else{
            return success("新增失败！");
        }

    }
    @Log(title = "基线模板修改", businessType = BusinessType.UPDATE)
    @PostMapping("/updateBaseFormWork")
    public AjaxResult updateBaseFormWork(@RequestBody BaseFormWork baseFormWork)
    {
        boolean b = BaseFormWorkService.updateById(baseFormWork);
        if(b){
            return success("修改成功！");
        }else{
            return success("修改失败！");
        }

    }

    @PostMapping("/queryBaseFormWorkById")
    public AjaxResult queryBaseFormWorkById(@RequestBody BaseFormWork baseFormWork)
    {
        BaseFormWork model = BaseFormWorkService.getById(baseFormWork.getId());
        return success(model);

    }




}
